//
//  CityCellOfLocalTravelNecessary.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/5.
//  Copyright © 2016年 KX. All rights reserved.
#import "WebViewOfCommendViewController.h"
#import "FreeTravelMacro.h"
#import "CityCellOfLocalTravelNecessary.h"
#import "CellOfCityCellOfLocalTravelNecessary.h"
#import "CityViewController.h"
#import "ModelOfLocal_basicCommendScenicSpotView.h"
@interface CityCellOfLocalTravelNecessary ()<UICollectionViewDelegate,UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionView;
@end
@implementation CityCellOfLocalTravelNecessary
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCollectionView];
    }
    return self;
}
- (void)createCollectionView{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    
    layout.sectionInset = UIEdgeInsetsMake(0, 10, 10, 10);
    layout.minimumLineSpacing = 10;
    layout.minimumInteritemSpacing = 10;
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
    layout.itemSize = CGSizeMake((SCREEN_WIDTH-30)/2,140);
    [self.contentView addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerClass:[CellOfCityCellOfLocalTravelNecessary class] forCellWithReuseIdentifier:@"CellOfCityCellOfLocalTravelNecessary"];
    [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CellOfMostPopularCommendScenicSpotViewHead"];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.collectionView.frame = self.contentView.bounds;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.model.local_basic.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    CellOfCityCellOfLocalTravelNecessary *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellOfCityCellOfLocalTravelNecessary" forIndexPath:indexPath];
    cell.model = self.model.local_basic[indexPath.row];
    return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    UICollectionReusableView *head = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CellOfMostPopularCommendScenicSpotViewHead" forIndexPath:indexPath];
    
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
        label.text = @"当地游必备";
        label.textAlignment = NSTextAlignmentCenter;
        
        label.font =  [UIFont fontWithName:@"Helvetica-Bold" size:15.f];
        [head addSubview:label];
    
    
    
    return head;
    
    
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    ModelOfLocal_basicCommendScenicSpotView *model = self.model.local_basic[indexPath.row];

    WebViewOfCommendViewController *vc = [[WebViewOfCommendViewController alloc]init];
    vc.url = [NSString stringWithFormat:@"http://m.qyer.com/z/deal/%@/?source=app&client_id=qyer_ios&track_app_version=7.0.1&track_deviceid=E9CA001A-5603-4CA8-B2EA-2BE34F691AC6",model.ID];
    CityViewController *cityVC = (CityViewController *)self.nextResponder.nextResponder.nextResponder.nextResponder;
    [cityVC.navigationController pushViewController:vc animated:YES];
    
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    return CGSizeMake(SCREEN_WIDTH, 50);
}
- (void)setModel:(ModelOfDataCommendScenicSpotView *)model{
    _model = model;
    [self.collectionView reloadData];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
